/**
 * HW17
 *
 * brief description of the program
 *
 * This program is released to public domain according to
 * author's wish, you can view full license at
 * http://tomatoeskit.org/upload/PublicDomainLicense.txt
 *
 * @author Fangning CHENG (Alpha.L Cheng) <chengf@purdue.edu>
 *
 * @lab LM4
 *
 * @date Oct 3, 2013
 *
 */

public class Pixel {
    private  int _rgb;
    public Pixel(int rgb)
    {
        _rgb = rgb;
    }
    
    public int getRed()
    {
        return  (_rgb >> 16) & 0xFF;
    }

    public int getGreen()
    {
        return  (_rgb >> 8) & 0xFF;
    }
    
    public int getBlue()
    {
        return  (_rgb) & 0xFF;
    }
    
    public void setRed(int red)
    {
        _rgb = 0x00FFFF & _rgb;
        int shRed = (red  & 0xFF) << 16; 
        _rgb = shRed | _rgb;
    }
    
    public void setGreen(int green)
    {
        _rgb = 0xFF00FF & _rgb;
        _rgb = ((green & 0xFF) << 8) | _rgb ;
    }
    
    public void setBlue(int blue)
    {
        _rgb = 0xFFFF00 & _rgb;
        _rgb = (blue & 0xFF) | _rgb;
    }
    
    public static void main(String[] args) {
        Pixel p1 = new Pixel(0xFFFF00FF);
        System.out.printf("rgb = (%2x, %2x, %2x)\n", p1.getRed(), p1.getGreen(), p1.getBlue());
        System.out.printf("rgb = (%d, %d, %d)\n", p1.getRed(), p1.getGreen(), p1.getBlue());
            
        Pixel p2 = new Pixel(0xFF43BF11);
        System.out.printf("rgb = (%2x, %2x, %2x)\n", p2.getRed(), p2.getGreen(), p2.getBlue());
        System.out.printf("rgb = (%d, %d, %d)\n", p2.getRed(), p2.getGreen(), p2.getBlue());
        
        Pixel p3 = new Pixel(0xFF000000);
        System.out.printf("rgb = (%d, %d, %d)\n", p3.getRed(), p3.getGreen(), p3.getBlue());

        p3.setRed(42);
        p3.setGreen(18);
        p3.setBlue(225);
        System.out.printf("rgb = (%d, %d, %d)\n", p3.getRed(), p3.getGreen(), p3.getBlue());
                
        p3.setRed(-1);
        p3.setGreen(500);
        p3.setBlue(1000);
        System.out.printf("rgb = (%d, %d, %d)\n", p3.getRed(), p3.getGreen(), p3.getBlue());

    }

}
